
from globally import LocalDataRootPath, os_name
import os

class RemovePack:
    def __init__(self, url ,packlist):
        self.url = url
        self.packlist = packlist

    # 删除软件包
    def remove(self):
        print("总计需要卸载： {}个包".format(len(self.packlist)))
        dirpath = self.__urltodir + 'Packages/'
        count = 0
        for packname in self.packlist:
            packpath = dirpath  + packname
            count = count + 1
            print("删除: {}/{}: {}".format(count, len(self.packlist), packname))
            os.remove(packpath)
            # print("删除软件包，PATH={}".format(packpath))

    # 通过url获取对应源地址存储于本地的具体路径
    @property
    def __urltodir(self):
        dirlist = self.url.split('/')[3:]
        dir = LocalDataRootPath + '/'.join(dirlist)
        if not os.path.exists(dir):
            os.makedirs(dir)
        return dir
